package com.itheima.youdianda.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.dto.RoleDataDto;
import com.itheima.youdianda.dto.RoleDto;
import com.itheima.youdianda.dto.RoleInfoDto;
import com.itheima.youdianda.dto.SysRoleMenuDto;
import com.itheima.youdianda.entity.RoleAdd;
import com.itheima.youdianda.entity.SysRole;
import com.itheima.youdianda.entity.SysRoleMenu;
import com.itheima.youdianda.service.SysRoleMenuService;
import com.itheima.youdianda.service.SysRoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;


    /**
     * 角色分页展示
     * @param page
     * @param limit
     * @param name
     * @return
     */
    @GetMapping("/list")
    public R<RoleDto> list(String page,String limit,String name){
        RoleDto roleList = sysRoleService.getRoleList(page, limit, name);
        return R.success(roleList);
    }

    /**
     * 添加角色数据
     * @param roleAdd
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody RoleAdd roleAdd){
        sysRoleService.add(roleAdd);
        return R.success("添加成功");
    }

    /**
     * 全部角色数据展示
     * @return
     */
    @GetMapping("/allData")
    public R<List<SysRole>> getAllData(){
        List<SysRole> allData = sysRoleService.getAllData();
        return R.success(allData);
    }

/*    *//**
     * 数据回显
     * @return
     *//*
    @GetMapping("/rowInfo")
    public R<RoleInfoDto> getRowInfo(String id){
        RoleInfoDto rowInfo = sysRoleService.getRowInfo(id);
        return R.success(rowInfo);
    }*/

    /**
     * 数据回显
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public R rowInfo(String id){
        SysRoleMenuDto sysRoleMenuDto = sysRoleService.rowInfo(id);
        return R.success(sysRoleMenuDto);
    }

    @PostMapping("/update")
    public R<String> update(@RequestBody SysRoleMenuDto sysRoleMenuDto){
        sysRoleService.updateRoleWithMenu(sysRoleMenuDto);
        return R.success("修改成功!");
    }

    @GetMapping("/del")
    public R<String> del(String id){
        sysRoleService.delRoleWithMenu(id);
        return R.success("删除成功!");
    }

}
